
  <template>
  <div class="bf-commont-template padding-t">

    <el-tabs :tab-position="'left'" v-model="activeName" @tab-click="handleClick" class="margin-l margin-r">
      <!-- <el-tab-pane label="合同公司 " name="first">
        <div class="clearfix bf-top-button">
          <div class="float-l">
            <el-button type="primary" @click="showTypeAdd">新增合同公司</el-button>
          </div>
          <div class="float-r">
            <div class="float-l">
              <el-input placeholder="请输入名称搜索内容" prefix-icon="el-icon-search" v-model="searchData" @keyup.enter.native="quickSearch">
              </el-input>
            </div>
            <div class="float-l padding-l">
            </div>
          </div>
        </div>
        <bf-table :data="recruitTypeData" :setting="recruitTypeSetting" :rowAction="rowAction1" @editSubmit="recruitTypeEditSubmit" @pageChange="pageChange" ref="table1"></bf-table>
      </el-tab-pane> -->
      <el-tab-pane label="工作地点" name="second">
        <div class="clearfix bf-top-button">
          <div class="float-l">
            <el-button type="primary" @click="showInterviewAdd">新增工作地点</el-button>
          </div>
          <div class="float-r">
            <div class="float-l">
              <el-input placeholder="请输入名称搜索内容" prefix-icon="el-icon-search" v-model="searchData" @keyup.enter.native="quickSearch">
              </el-input>
            </div>
            <div class="float-l padding-l">
              <!-- <el-button type="primary" @click="showSearch">高级筛选</el-button> -->
            </div>
          </div>
        </div>
        <bf-table :data="interviewProblemData" :setting="interviewProblemSetting" :rowAction="rowAction2" @editSubmit="interviewProblemEditSubmit" @pageChange="pageChange" ref="table2"></bf-table>
      </el-tab-pane>

    </el-tabs>
    <!-- 添加 -->
    <bf-table-add :editForm='recruitTypeAddSetting' ref='recruitTypeRef' @formSubmit='addRecruitTypeSubmit' :editRules="addRules"></bf-table-add>
    <!-- 添加 -->
    <bf-table-add :editForm='interviewProblemAddSetting' ref='interviewProblemRef' @formSubmit='addInterviewProblemSubmit' :editRules="addRules"></bf-table-add>

    <!--编辑 -->
    <bf-table-edit :editForm='recruitTypeSetting' ref='editRecruitTypeRef' @formSubmit='editRecruitTypeSubmit' :editRules="addRules"></bf-table-edit>
    <!-- 编辑-->
    <bf-table-edit :editForm='interviewProblemSetting' ref='editInterviewProblemRef' @formSubmit='editInterviewProblemSubmit' :editRules="addRules"></bf-table-edit>
  </div>
</template>

<script>
/** @
 * addParameterChannel,新增渠道
 * addParameterQuestion,新增题库
 * addParameterEliminate ,新增淘汰原因
 */
import { getRecruitType, getInterviewProblem, addParameter, editParameter, deleteParameter } from './api.js'
import { recruitTypeSetting, interviewProblemSetting, recruitTypeAddSetting, interviewProblemAddSetting } from './table.setting.js'

export default {
  data() {
    return {
      searchData: '',
      activeName: 'second',
      recruitTypeData: {},
      interviewProblemData: {},
      obsoleteData: {},
      recruitTypeSetting: recruitTypeSetting,
      interviewProblemSetting: interviewProblemSetting,
      recruitTypeAddSetting: recruitTypeAddSetting,
      interviewProblemAddSetting: interviewProblemAddSetting,
      userData: {
      },
      rowAction1: [
        {
          label: '查看',
          click: (item) => {
            this.$refs.table1.showDetail(item)
          }
        },
        {
          label: '编辑',
          click: (item) => {
            this.$refs.editRecruitTypeRef.show(item.scope)
          }
        },
        {
          label: '删除',
          click: (item) => {
            this.$refs.table1.showDelete(item)
          }
        }
      ],
      rowAction2: [
        {
          label: '查看',
          click: (item) => {
            this.$refs.table2.showDetail(item)
          }
        },
        {
          label: '编辑',
          click: (item) => {
            this.$refs.editInterviewProblemRef.show(item.scope)
          }
        },
        {
          label: '删除',
          click: (item) => {
            this.$refs.table2.showDelete(item)
          }
        }
      ],
      addRules: {
        itemText: [
          { required: true, message: '必填项', trigger: 'blur' }
        ]
      },
      searchParams: { // 搜索条件
        page: 1
      }
    }
  },
  mounted: function() {
    this.searchList()
  },
  methods: {
    addRecruitTypeSubmit(form) { // 新增合同公司
      const param = {
        paramCode: 'CONTRACTCOMPANY',
      }
      const obj = Object.assign(form, param)
      addParameter(obj).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.recruitTypeRef.hiden()
          this.searchList()
        }
      })
    },
    addInterviewProblemSubmit(form) { // 新增工作地址
      const param = {
        paramCode: 'WORKPLACE',
      }
      const obj = Object.assign(form, param)
      addParameter(obj).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.interviewProblemRef.hiden()
          this.searchList()
        }
      })
    },

    editRecruitTypeSubmit(form) { // 编辑保存渠道
      editParameter(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.editRecruitTypeRef.hiden()
          this.searchList()
        }
      })
    },
    editInterviewProblemSubmit(form) { // 编辑保存题库
      editParameter(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.editInterviewProblemRef.hiden()
          this.searchList()
        }
      })
    },
    recruitTypeEditSubmit(params, formType, formList) { // 删除
      if (formType === 'delete') {
        const obj = params.row
        deleteParameter(obj).then(response => {
          if (response.success) {
            this.$message({
              message: '删除成功!',
              type: 'success'
            })
          }
          this.searchList()
        })
      }
    },

    interviewProblemEditSubmit(params, formType, formList) { // 删除
      if (formType === 'delete') {
        const obj = params.row
        deleteParameter(obj).then(response => {
          if (response.success) {
            this.$message({
              message: '删除成功!',
              type: 'success'
            })
          }
          this.searchList()
        })
      }
    },
    pageChange(pageObj) {
      this.searchParams.page = pageObj.page
      this.searchParams.pageSize = pageObj.pageSize
      this.searchList()
    },
    showSearch() {
      this.$refs.table.showSearch()
    },
    showTypeAdd() {
      this.activeName = 'first'
      this.$refs.recruitTypeRef.show()
    },
    showInterviewAdd() {
      this.activeName = 'second'
      this.$refs.interviewProblemRef.show()
    },
    quickSearch() {
      this.searchParams.page = 1
      this.searchParams.itemText = this.searchData
      this.searchList()
    },
    handleClick(tab, event) {
      this.searchParams.page = 1
      this.searchList()
    },
    searchList() {
      if (this.activeName == 'first') {
        this.searchParams.paramCode = 'CONTRACTCOMPANY'
        getRecruitType(this.searchParams).then(response => {
          this.recruitTypeData = response
        })
      }
      if (this.activeName == 'second') {
        this.searchParams.paramCode = 'WORKPLACE'
        getInterviewProblem(this.searchParams).then(response => {
          this.interviewProblemData = response
        })
      }
    }
  }
}
</script>

<style scoped>

</style>
